package com.hadooop.topN;

import java.util.Comparator;
import java.util.PriorityQueue;

public class Test {

    public static void main(String[] args) {
        int[] arr = {1, 10, 5, 3, 8, 9};
        PriorityQueue<Integer> pq = new PriorityQueue<Integer>(3, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });
        for (int i = 0; i < arr.length; i++) {
            pq.add(arr[i]);
            if (pq.size() > 3) {
                pq.poll();
            }
        }
        System.out.println(pq);
    }

}
